<?php
	/**
	 * Error handler
	 *
	 */
	class Errors
	{
		public $error = array();
		public $display = 0;
		
	    /**
		 * Sets user errors
		 *
		 * @param string $error_type error type
		 * @param string $error_string error string
		 * @param string $error_filename file name, where the error occured
		 * @param string $error_line line in the file, where the error occured
		*/		
		function SetError($error_type, $error_string, $error_filename='no', $error_line='no')
		{	
			if (($error_type==2)&&(DEBUG_MODE>=2))
			{ 
				$this->error['type']='Warning';
				$this->display = 1;
			}
			elseif ((($error_type==2048)||($error_type==8))&&(DEBUG_MODE>=3))
			{ 
				$this->error['type']='Run-time notice';
				$this->display = 1;
			}
			elseif (($error_type==1)&&(DEBUG_MODE>=1))
			{ 
				$this->error['type']='Fatal Error';
				$this->display = 1;
			}
			elseif (($error_type!=1)&&($error_type!=2)&&($error_type!=2048)&&($error_type!=8)) 
			{
				$this->error['type']=$error_type;
				$this->display = 1;
			}
			$this->error['message']=$error_string;
			$this->error['filename']=$error_filename;
			$this->error['line']=$error_line;
			if ($this->display)
			{
				if (($error_type!=2048)&&($error_type!=8)) $this->writeLog();
				$this->displayError();
			}
		}
		
		/**
		 * Generates error log string
		 *
		 */
		function WriteLog()
		{
			$error_log_text = '('.date('H:i:s d.m.Y').') '.$this->error['type'].': '.$this->error['message'].
				' in '.$this->error['filename'].
				' on '.$this->error['line']."\r\n";
			error_log($error_log_text, 3, APP.SEPARATOR.'app_error.log');
		}
		
	    /**
		 * Displays the error on the page
		*/		
		function DisplayError()
		{
			$error_text = '<font color="red">'.$this->error['type'].'</font>'.
				': <b>'.$this->error['message'].
				'</b> occurred in the file <b>'.$this->error['filename'].'</b>'.
				' on line <b>'.$this->error['line'].'</b><br />';
			echo $error_text;			
		}
	}
?>